﻿// Copyright (c) ZhangPeihang. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using LaserMark.ModbusTCP;
using LaserMark.ModbusTCP.Abstraction;
using LaserMark.ModbusTCP.Config;

namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceCollectionExtension
{
    public static IServiceCollection AddModBus(this IServiceCollection service, Func<ModBusOption, Task> setupAction)
    {
        service.AddOptions<ModBusOption>();
        service.Configure<ModBusOption>(option =>
        {
            option.Provider = service.BuildServiceProvider();
            setupAction?.Invoke(option);
        });
        service.AddScoped<IMasterClientFactory, MasterClientFactory>();
        return service;
    }
}
